package com.lianyu507.api;

import com.lianyu507.bean.PagingProperties;
import com.lianyu507.pojo.CrArticle;
import com.lianyu507.pojo.CrArticleExample;
import com.lianyu507.service.ArticleContentShowService;
import com.lianyu507.service.CrArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * =================================
 * <p>
 * Created by Administrator on 2017/11/22.
 * <p>
 * 描述:
 */
@Controller
@RequestMapping("/html/v1/article")
public class ArticleContentShowController extends BaseController {

    //操作的是cr_article表，是根据表的id找到表里面的所有内容（文章内容）  然后返给前端json进行展现

    @Autowired
    private ArticleContentShowService articleContentShowService;

    @Autowired
    private CrArticleService crArticleService;


    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getList(PagingProperties paging){

        CrArticleExample crArticleExample=new CrArticleExample();
        if(paging.getNeedPaging()) {
            paging.setTotal(crArticleService.countByExample(crArticleExample));
            crArticleExample.setOrderByClause(" id desc " + paging.build());
        }
        List<CrArticle> articleList=this.crArticleService.selectByExample(crArticleExample);

        return this.successPageList(paging,articleList);

    }


    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getArticle(Integer id){
        CrArticle crArticle = this.articleContentShowService.getArticleContent(id);
        return this.successResult(crArticle);

    }


}
